<template>
  <div class="header">
    <h1>我是头部</h1>
    <p>count的值是{{count }}</p>
    <p>价格是{{ price }}</p>
    <p>电影列表总长度{{movieList.length}}</p>

    <button @click="increment">累加count的值</button>
    <button @click="incrementN({n:3})">count每次加n</button>

    <button @click='incrementWait'>等待2秒后再加</button>
    <button @click='incrementNWait({n:5})'>等待2秒后再加</button>
  </div>
</template>

<script>
import { mapMutations, mapState } from "vuex";

export default {
  name: "Header",
  computed: {
    ...mapState(["count", "price", "movieList"]),
  },
  methods: {
    ...mapMutations(["increment", "incrementN"]),
    // increment() {
    //   this.$store.commit("increment");
    // },
    // incrementN(n) {
    //   this.$store.commit("incrementN", { n });
    // },

    incrementWait() {
        //因为我们要先分发action,
        // 所以派发action使用$store.dispatch方法
      this.$store.dispatch("incrementWait");
    },

    incrementNWait(payload){
      this.$store.dispatch("incrementNWait", payload)
    }
  },
};
</script>

<style scoped>
.header {
  margin: 30px;
  background: yellowgreen;
}
</style>